package database;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import database.model.Article;
import database.model.Section;


public class TestDatabase {
	public static void main(String[] args) throws HibernateException {

		/*SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
		session =sessionFactory.openSession();
		Transaction tx = session.beginTransaction();
		System.out.println("Inserting Record");
		Section section = new Section();
		section.setTitle("toto");

		session.save(section);
		tx.commit();
		System.out.println("Done");

		// Actual contact insertion will happen at this step
		session.flush();
		session.close();*/
		/*Session session = HibernateUtil.currentSession();
		Transaction trans = session.beginTransaction();
		@SuppressWarnings("unchecked")
		List<Section> res = session.createSQLQuery("select * from SECTION WHERE title = 'toto'").addEntity(Section.class).list();
		trans.commit();
		HibernateUtil.closeSession();*/
		/*Section section = Section.getSectionWithUrl("toto");
		System.out.println(section.getTitle());*/
    }

    private void createAndStoreSection() throws HibernateException {
    	Session session = HibernateUtil.currentSession();
    	   
    	Transaction tx = session.beginTransaction();

        Section section = new Section();
        section.setTitle("toto");
        
        session.save(section);

        tx.commit();

        HibernateUtil.closeSession();
    }
}
